package vip.zhaotao.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class TestController {

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "testError")
    @GetMapping("/test")
    public String test() {
        return restTemplate.getForObject("http://service-provider/test", String.class) + "，Ribbon实现。";
    }

    public String testError() {
        return "服务提供者未启动或异常！！！";
    }
}
